package com.tinymall.controller;

import com.tinymall.common.pojo.dto.UserDTO;
import com.tinymall.common.pojo.vo.UserVO;
import com.tinymall.common.restful.ResponseData;
import com.tinymall.common.restful.ResponseDataUtils;
import com.tinymall.service.IUserService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: 用户控制器
 * @Author: TX
 * @Date: 2022/7/5 10:40
 * @Version: V1.0.0
 */
@RestController
@Validated
@CrossOrigin
@Slf4j
@RequestMapping(value = "/user", produces = "application/json;charset=utf-8")
@Api("用户模块")
public class UserController {
    @Autowired
    private IUserService userService;

    @PostMapping("/register")
    public  ResponseData reg(@Validated @RequestBody UserDTO userDTO) {
        log.info("进入/user/register处理器中");
        userService.reg(userDTO);
        return ResponseDataUtils.buildSuccess("1", "用户注册成功！！！");
    }
    @PostMapping("/login")
    public  ResponseData login(@Validated @RequestBody UserDTO userDTO) {
        log.info("进入/user/login处理器中");
        UserVO loginData = userService.login(userDTO);
        return ResponseDataUtils.buildSuccess("0", "用户登录成功！！！",loginData);
    }
}
